// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ORDER_OMI_O23 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("21 ORC",21)]
  	    [HL7Field(HL7Version.v25, 21, HL7Repeat.False, HL7Required.True,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("22 TIMING",22)]
  	    [HL7Field(HL7Version.v25, 22, HL7Repeat.True, HL7Required.False,"TIMING_OMI_O23")]
	    public TIMING_OMI_O23[] TIMING {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("26 OBR",26)]
  	    [HL7Field(HL7Version.v25, 26, HL7Repeat.False, HL7Required.True,"OBR")]
	    public OBR OBR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("27 NTE",27)]
  	    [HL7Field(HL7Version.v25, 27, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("28 CTD",28)]
  	    [HL7Field(HL7Version.v25, 28, HL7Repeat.False, HL7Required.False,"CTD")]
	    public CTD CTD {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("29 DG1",29)]
  	    [HL7Field(HL7Version.v25, 29, HL7Repeat.True, HL7Required.False,"DG1")]
	    public DG1[] DG1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("30 OBSERVATION",30)]
  	    [HL7Field(HL7Version.v25, 30, HL7Repeat.True, HL7Required.False,"OBSERVATION_OMI_O23")]
	    public OBSERVATION_OMI_O23[] OBSERVATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("34 IPC",34)]
  	    [HL7Field(HL7Version.v25, 34, HL7Repeat.True, HL7Required.True,"IPC")]
	    public IPC[] IPC {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			TIMING = ProcessGroupArray<TIMING_OMI_O23>(availableData, options, "TIMING");
			OBR = PopSegmentParseAndCheckRequired<OBR>(availableData, options, "OBR");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			CTD = PopSegmentParseAndCheckRequired<CTD>(availableData, options, "CTD");
			DG1 = PopSegmentParseAndCheckRequiredArray<DG1>(availableData, options, "DG1");
			OBSERVATION = ProcessGroupArray<OBSERVATION_OMI_O23>(availableData, options, "OBSERVATION");
			IPC = PopSegmentParseAndCheckRequiredArray<IPC>(availableData, options, "IPC");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			TIMING_OMI_O23 testTIMING_OMI_O23 = new TIMING_OMI_O23();
			bool grpCCTIMING_OMI_O23 = (testTIMING_OMI_O23.CanConsume(availableData, options));
			if (IsRequired("TIMING", options.Version) || grpCCTIMING_OMI_O23) {
				return grpCCTIMING_OMI_O23;
			}
			bool isOBR = availableData.StartsWith("OBR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBR", options.Version) || isOBR) {
				return isOBR;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			bool isCTD = availableData.StartsWith("CTD", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CTD", options.Version) || isCTD) {
				return isCTD;
			}
			bool isDG1 = availableData.StartsWith("DG1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("DG1", options.Version) || isDG1) {
				return isDG1;
			}
			OBSERVATION_OMI_O23 testOBSERVATION_OMI_O23 = new OBSERVATION_OMI_O23();
			bool grpCCOBSERVATION_OMI_O23 = (testOBSERVATION_OMI_O23.CanConsume(availableData, options));
			if (IsRequired("OBSERVATION", options.Version) || grpCCOBSERVATION_OMI_O23) {
				return grpCCOBSERVATION_OMI_O23;
			}
			bool isIPC = availableData.StartsWith("IPC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("IPC", options.Version) || isIPC) {
				return isIPC;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ORDER";
			}
        }

        static ORDER_OMI_O23() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ORDER_OMI_O23));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (TIMING != null && TIMING.Length > 0) {
			for (int i = 0; i < TIMING.Length; i++) {
				string segmentValue = TIMING[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBR != null) {
			string segmentValue = OBR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (CTD != null) {
			string segmentValue = CTD.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (DG1 != null && DG1.Length > 0) {
			for (int i = 0; i < DG1.Length; i++) {
				string segmentValue = DG1[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBSERVATION != null && OBSERVATION.Length > 0) {
			for (int i = 0; i < OBSERVATION.Length; i++) {
				string segmentValue = OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (IPC != null && IPC.Length > 0) {
			for (int i = 0; i < IPC.Length; i++) {
				string segmentValue = IPC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

